import asyncio
import websockets
import datetime


async def handler(websocket, path):
    data = await websocket.recv()
    reply = f"Data received as {data}!"
    print(datetime.datetime.now(), data, ']]]]', reply)
    await websocket.send(reply)


if '__main__' == __name__:

    start_server = websockets.serve(handler, '0.0.0.0', 7771)

    asyncio.get_event_loop().run_until_complete(start_server)
    asyncio.get_event_loop().run_forever()
